package nc.tf.rest2025;

import com.alibaba.fastjson.JSONObject;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.server.ISecurityTokenCallback;
import nc.tf.service2025.IRedSaleInvoiceSaveService;
import nc.tf.service2025.ISaleInvoiceSaveService;
import nc.vo.scmpub.api.rest.utils.RestUtils;
import nc.vo.scmpub.res.Module;
import org.json.JSONString;
import uap.ws.rest.resource.AbstractUAPRestResource;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("so/service")
public class SaleInvoiceRestResource extends AbstractUAPRestResource {

	@POST
	@Path("/invoice/saveAndApprove")
	@Consumes({ "application/json" })
	@Produces({ "application/json" })
	public JSONString invoiceSave(JSONObject jsonDTO) throws Exception {
		dobeforeaction();
		ISaleInvoiceSaveService service = NCLocator.getInstance().lookup(ISaleInvoiceSaveService.class);
		JSONObject result = service.synBillSave_RequiresNew(jsonDTO);
		return RestUtils.toJSONString(result);
	}

	@POST
	@Path("/redInk/saveAndApprove")
	@Consumes({ "application/json" })
	@Produces({ "application/json" })
	public JSONString redInkSave(JSONObject jsonDTO) throws Exception {
		dobeforeaction();
		IRedSaleInvoiceSaveService service = NCLocator.getInstance().lookup(IRedSaleInvoiceSaveService.class);
		JSONObject result = service.synBillSave_RequiresNew(jsonDTO);
		return RestUtils.toJSONString(result);
	}

	public void dobeforeaction() {
		ISecurityTokenCallback sc = (ISecurityTokenCallback) NCLocator.getInstance().lookup(ISecurityTokenCallback.class);
		sc.token("NCSystem".getBytes(), "pfxx".getBytes());
	}

	@Override
	public String getModule() {
		return Module.SO.getName();
	}

}
